package anims;
import java.applet.Applet;
import java.awt.Color;
import java.awt.Frame;
import java.awt.Graphics;
import java.awt.Image;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;

public class DoubleApplet extends Applet
{
  /**
   * When this class is ran as an application, how wide should it be.
   */
  public static final int IDEAL_WIDTH = 640;

  /**
   * When this class is ran as an application, how tall should it be.
   */
  public static final int IDEAL_HEIGHT = 480;

  /**
   * This method paints the display.
   *
   * @param g The graphics object to paint to.
   */
  public void paint(Graphics g)
  {
    final int size = 128;

    Image image = createImage(size + 1, size + 1);
    Graphics offG = image.getGraphics();

    offG.setColor(Color.BLACK);
    offG.fillRect(0, 0, getWidth(), getHeight());

    for (int i = 0; i < size; i++)
    {
      int c = i * 5;
      c = Math.min(c, 255);
      offG.setColor(new Color(c, 0, 0));
      offG.fillOval(i, i, size - (i * 2), size - (i * 2));
    }

    g.setColor(Color.BLACK);
    g.fillRect(0, 0, getWidth(), getHeight());

    for (int y = 0; y < getHeight() / size; y++)
    {
      for (int x = 0; x < getWidth() / size; x++)
      {
        g.drawImage(image, x * size, y * size, null);
      }
    }
  }

  /**
   * The main method is called when the class is to be ran
   * as a Java application. This method creates a frame and
   * attaches the applet to the frame.
   *
   * @param args Not used.
   */
  public static void main(String args[])
  {
    DoubleApplet applet = new DoubleApplet();
    Frame frame = new Frame();
    frame.addWindowListener(new WindowAdapter()
    {
      public void windowClosing(WindowEvent e)
      {
        System.exit(0);
      }
    });

    frame.add(applet);
    frame.setSize(IDEAL_WIDTH, IDEAL_HEIGHT);
    frame.show();
    applet.init();
  }

}